/*
 * @Author: 大旗云业务部-黄龙
 * @Date: 2023-09-12 10:28:42
 * @LastEditors: 大旗云业务部-黄龙
 * @LastEditTime: 2023-09-12 11:27:38
 * @Description: 用户信息store
 */
import config from '@/config';
import type { IBaseUserInfo } from '@/interfaces/i-user-info';
import { defineStore } from 'pinia';
import { ref } from 'vue';

// 定义状态尽量使用use开头，store结尾
export const useUserInfoStore = defineStore(
	'useUserInfoStore',
	() => {
		const token = ref('dce2364be31e421c949c7b2cae7625d9');
		const encryptionType = ref('');
		const userInfo = ref<IBaseUserInfo>({
			phone: '',
			username: '',
			email: ''
		});

		const setToken = (val: string) => {
			token.value = val;
		};

		// const setEncryptionType = (val: string) => {
		//   encryptionType.value = val;
		// };

		const setUserInfo = (info: IBaseUserInfo) => {
			userInfo.value = info;
		};

		return { token, encryptionType, userInfo, setToken, setUserInfo };
	},
	{
		// 数据持久化配置，设为true即所有变量都进行持久化：persist: true
		// persist: true
		// 也可针对具体变量进行持久化
		persist: [
			{
				// 存储唯一标识
				key: config.storageKey.token,
				// 存储方式: 默认localStorage
				// storage: window.localStorage,
				// 当前需存储的变量
				paths: ['token']
			},
			// {
			//   key: config.storageKey.encryptionType,
			//   paths: ['encryptionType']
			// },
			{
				key: config.storageKey.userInfo,
				paths: ['userInfo']
			}
		]
	}
);
